In [1]:
%matplotlib inline
import numpy as np
import scipy.optimize as optimize
import math
In [2]:
#заданная функция
def f(x):
return np.sin(x/5.0) * np.exp(x/10.0) + 5 * np.exp (-x/2.0)
bounds = [(1.0,30.0)]
result = optimize.differential_evolution(f,bounds)
In [3]:
result
Out[3]:
In [4]:
file_obj = open('result-week3-Task2.txt', 'w')
file_obj.write(str(round(result.fun,2)))
file_obj.close()
In [5]:
# сравнил эффективность
x_val = 30
res = optimize.minimize(f,x_val,method="BFGS")
In [6]:
res
Out[6]:
In [ ]: